package com.gy.common.vaild;


import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.HashSet;
import java.util.Set;

public class ListStatusConstraintVaildator implements ConstraintValidator<ListStatus, Integer> {

    private Set<Integer> set = new HashSet<>();
    @Override
    public void initialize(ListStatus constraintAnnotation) {
        int[] vals = constraintAnnotation.vals();
        for (int i = 0; i < vals.length; i++) {
            set.add(vals[i]);
        }
    }
    /**
     *
     * @param value 为用户传过来的值
     * @param context
     * @return
     */
    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext context) {
        return set.contains(value);
    }
}
